
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>django.contrib.gis.measure &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../../../../genindex.html" />
    <link rel="search" title="搜索" href="../../../../search.html" />



 
<script src="../../../../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../../../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    <a href="../../../index.html" title="模块代码" accesskey="U">up</a></div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="_modules-django-contrib-gis-measure">
            
  <h1>django.contrib.gis.measure 源代码</h1><div class="highlight"><pre>
<span></span><span class="c1"># Copyright (c) 2007, Robert Coup &lt;robert.coup@onetrackmind.co.nz&gt;</span>
<span class="c1"># All rights reserved.</span>
<span class="c1">#</span>
<span class="c1"># Redistribution and use in source and binary forms, with or without modification,</span>
<span class="c1"># are permitted provided that the following conditions are met:</span>
<span class="c1">#</span>
<span class="c1">#   1. Redistributions of source code must retain the above copyright notice,</span>
<span class="c1">#      this list of conditions and the following disclaimer.</span>
<span class="c1">#</span>
<span class="c1">#   2. Redistributions in binary form must reproduce the above copyright</span>
<span class="c1">#      notice, this list of conditions and the following disclaimer in the</span>
<span class="c1">#      documentation and/or other materials provided with the distribution.</span>
<span class="c1">#</span>
<span class="c1">#   3. Neither the name of Distance nor the names of its contributors may be used</span>
<span class="c1">#      to endorse or promote products derived from this software without</span>
<span class="c1">#      specific prior written permission.</span>
<span class="c1">#</span>
<span class="c1"># THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND</span>
<span class="c1"># ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span>
<span class="c1"># WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span>
<span class="c1"># DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR</span>
<span class="c1"># ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES</span>
<span class="c1"># (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span>
<span class="c1"># LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON</span>
<span class="c1"># ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<span class="c1"># (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<span class="c1"># SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<span class="c1">#</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Distance and Area objects to allow for sensible and convenient calculation</span>
<span class="sd">and conversions.</span>

<span class="sd">Authors: Robert Coup, Justin Bronn, Riccardo Di Virgilio</span>

<span class="sd">Inspired by GeoPy (https://github.com/geopy/geopy)</span>
<span class="sd">and Geoff Biggs&#39; PhD work on dimensioned units for robotics.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">decimal</span> <span class="kn">import</span> <span class="n">Decimal</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">total_ordering</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;Area&#39;</span><span class="p">,</span> <span class="s1">&#39;D&#39;</span><span class="p">,</span> <span class="s1">&#39;Distance&#39;</span><span class="p">]</span>

<span class="n">NUMERIC_TYPES</span> <span class="o">=</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="n">Decimal</span><span class="p">)</span>
<span class="n">AREA_PREFIX</span> <span class="o">=</span> <span class="s2">&quot;sq_&quot;</span>


<span class="k">def</span> <span class="nf">pretty_name</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">obj</span><span class="o">.</span><span class="vm">__name__</span> <span class="k">if</span> <span class="n">obj</span><span class="o">.</span><span class="vm">__class__</span> <span class="o">==</span> <span class="nb">type</span> <span class="k">else</span> <span class="n">obj</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>


<span class="nd">@total_ordering</span>
<span class="k">class</span> <span class="nc">MeasureBase</span><span class="p">:</span>
    <span class="n">STANDARD_UNIT</span> <span class="o">=</span> <span class="kc">None</span>
    <span class="n">ALIAS</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="n">UNITS</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="n">LALIAS</span> <span class="o">=</span> <span class="p">{}</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">default_unit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">value</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">default_units</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">STANDARD_UNIT</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">default_unit</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">default_unit</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span> <span class="o">=</span> <span class="n">default_unit</span>

    <span class="k">def</span> <span class="nf">_get_standard</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">STANDARD_UNIT</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_standard</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">STANDARD_UNIT</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>

    <span class="n">standard</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_standard</span><span class="p">,</span> <span class="n">_set_standard</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">UNITS</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">UNITS</span><span class="p">[</span><span class="n">name</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="s1">&#39;Unknown unit type: </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">(</span><span class="si">%s</span><span class="s1">=</span><span class="si">%s</span><span class="s1">)&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">pretty_name</span><span class="p">(</span><span class="bp">self</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span><span class="p">,</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span><span class="p">))</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span><span class="p">)</span>

    <span class="c1"># **** Comparison methods ****</span>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">standard</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">NotImplemented</span>

    <span class="k">def</span> <span class="fm">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">standard</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__lt__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">&lt;</span> <span class="n">other</span><span class="o">.</span><span class="n">standard</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">NotImplemented</span>

    <span class="c1"># **** Operators methods ****</span>

    <span class="k">def</span> <span class="fm">__add__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span>
                <span class="n">default_unit</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span><span class="p">,</span>
                <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">STANDARD_UNIT</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">+</span> <span class="n">other</span><span class="o">.</span><span class="n">standard</span><span class="p">)}</span>
            <span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%(class)s</span><span class="s1"> must be added with </span><span class="si">%(class)s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">{</span><span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="n">pretty_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)})</span>

    <span class="k">def</span> <span class="fm">__iadd__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">+=</span> <span class="n">other</span><span class="o">.</span><span class="n">standard</span>
            <span class="k">return</span> <span class="bp">self</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%(class)s</span><span class="s1"> must be added with </span><span class="si">%(class)s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">{</span><span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="n">pretty_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)})</span>

    <span class="k">def</span> <span class="fm">__sub__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span>
                <span class="n">default_unit</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span><span class="p">,</span>
                <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">STANDARD_UNIT</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">-</span> <span class="n">other</span><span class="o">.</span><span class="n">standard</span><span class="p">)}</span>
            <span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%(class)s</span><span class="s1"> must be subtracted from </span><span class="si">%(class)s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">{</span><span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="n">pretty_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)})</span>

    <span class="k">def</span> <span class="fm">__isub__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">-=</span> <span class="n">other</span><span class="o">.</span><span class="n">standard</span>
            <span class="k">return</span> <span class="bp">self</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%(class)s</span><span class="s1"> must be subtracted from </span><span class="si">%(class)s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">{</span><span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="n">pretty_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)})</span>

    <span class="k">def</span> <span class="fm">__mul__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">NUMERIC_TYPES</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span>
                <span class="n">default_unit</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span><span class="p">,</span>
                <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">STANDARD_UNIT</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">*</span> <span class="n">other</span><span class="p">)}</span>
            <span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%(class)s</span><span class="s1"> must be multiplied with number&#39;</span> <span class="o">%</span> <span class="p">{</span><span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="n">pretty_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)})</span>

    <span class="k">def</span> <span class="fm">__imul__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">NUMERIC_TYPES</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">*=</span> <span class="nb">float</span><span class="p">(</span><span class="n">other</span><span class="p">)</span>
            <span class="k">return</span> <span class="bp">self</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%(class)s</span><span class="s1"> must be multiplied with number&#39;</span> <span class="o">%</span> <span class="p">{</span><span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="n">pretty_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)})</span>

    <span class="k">def</span> <span class="fm">__rmul__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span> <span class="o">*</span> <span class="n">other</span>

    <span class="k">def</span> <span class="fm">__truediv__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">/</span> <span class="n">other</span><span class="o">.</span><span class="n">standard</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">NUMERIC_TYPES</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span>
                <span class="n">default_unit</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span><span class="p">,</span>
                <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">STANDARD_UNIT</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">/</span> <span class="n">other</span><span class="p">)}</span>
            <span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%(class)s</span><span class="s1"> must be divided with number or </span><span class="si">%(class)s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">{</span><span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="n">pretty_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)})</span>

    <span class="k">def</span> <span class="fm">__itruediv__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">NUMERIC_TYPES</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">/=</span> <span class="nb">float</span><span class="p">(</span><span class="n">other</span><span class="p">)</span>
            <span class="k">return</span> <span class="bp">self</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%(class)s</span><span class="s1"> must be divided with number&#39;</span> <span class="o">%</span> <span class="p">{</span><span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="n">pretty_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)})</span>

    <span class="k">def</span> <span class="fm">__bool__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">standard</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">default_units</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the unit value and the default units specified</span>
<span class="sd">        from the given keyword arguments dictionary.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">val</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="n">default_unit</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">STANDARD_UNIT</span>
        <span class="k">for</span> <span class="n">unit</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">float</span><span class="p">):</span>
                <span class="n">value</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">unit</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">UNITS</span><span class="p">:</span>
                <span class="n">val</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">UNITS</span><span class="p">[</span><span class="n">unit</span><span class="p">]</span> <span class="o">*</span> <span class="n">value</span>
                <span class="n">default_unit</span> <span class="o">=</span> <span class="n">unit</span>
            <span class="k">elif</span> <span class="n">unit</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ALIAS</span><span class="p">:</span>
                <span class="n">u</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ALIAS</span><span class="p">[</span><span class="n">unit</span><span class="p">]</span>
                <span class="n">val</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">UNITS</span><span class="p">[</span><span class="n">u</span><span class="p">]</span> <span class="o">*</span> <span class="n">value</span>
                <span class="n">default_unit</span> <span class="o">=</span> <span class="n">u</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">lower</span> <span class="o">=</span> <span class="n">unit</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">lower</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">UNITS</span><span class="p">:</span>
                    <span class="n">val</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">UNITS</span><span class="p">[</span><span class="n">lower</span><span class="p">]</span> <span class="o">*</span> <span class="n">value</span>
                    <span class="n">default_unit</span> <span class="o">=</span> <span class="n">lower</span>
                <span class="k">elif</span> <span class="n">lower</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">LALIAS</span><span class="p">:</span>
                    <span class="n">u</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">LALIAS</span><span class="p">[</span><span class="n">lower</span><span class="p">]</span>
                    <span class="n">val</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">UNITS</span><span class="p">[</span><span class="n">u</span><span class="p">]</span> <span class="o">*</span> <span class="n">value</span>
                    <span class="n">default_unit</span> <span class="o">=</span> <span class="n">u</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="s1">&#39;Unknown unit type: </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">unit</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">val</span><span class="p">,</span> <span class="n">default_unit</span>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">unit_attname</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">unit_str</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Retrieve the unit attribute name for the given unit string.</span>
<span class="sd">        For example, if the given unit string is &#39;metre&#39;, return &#39;m&#39;.</span>
<span class="sd">        Raise an exception if an attribute cannot be found.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">lower</span> <span class="o">=</span> <span class="n">unit_str</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">unit_str</span> <span class="ow">in</span> <span class="bp">cls</span><span class="o">.</span><span class="n">UNITS</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">unit_str</span>
        <span class="k">elif</span> <span class="n">lower</span> <span class="ow">in</span> <span class="bp">cls</span><span class="o">.</span><span class="n">UNITS</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">lower</span>
        <span class="k">elif</span> <span class="n">lower</span> <span class="ow">in</span> <span class="bp">cls</span><span class="o">.</span><span class="n">LALIAS</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">LALIAS</span><span class="p">[</span><span class="n">lower</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;Could not find a unit keyword associated with &quot;</span><span class="si">%s</span><span class="s1">&quot;&#39;</span> <span class="o">%</span> <span class="n">unit_str</span><span class="p">)</span>


<div class="viewcode-block" id="Distance"><a class="viewcode-back" href="../../../../ref/contrib/gis/measure.html#django.contrib.gis.measure.Distance">[文档]</a><span class="k">class</span> <span class="nc">Distance</span><span class="p">(</span><span class="n">MeasureBase</span><span class="p">):</span>
    <span class="n">STANDARD_UNIT</span> <span class="o">=</span> <span class="s2">&quot;m&quot;</span>
    <span class="n">UNITS</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;chain&#39;</span><span class="p">:</span> <span class="mf">20.1168</span><span class="p">,</span>
        <span class="s1">&#39;chain_benoit&#39;</span><span class="p">:</span> <span class="mf">20.116782</span><span class="p">,</span>
        <span class="s1">&#39;chain_sears&#39;</span><span class="p">:</span> <span class="mf">20.1167645</span><span class="p">,</span>
        <span class="s1">&#39;british_chain_benoit&#39;</span><span class="p">:</span> <span class="mf">20.1167824944</span><span class="p">,</span>
        <span class="s1">&#39;british_chain_sears&#39;</span><span class="p">:</span> <span class="mf">20.1167651216</span><span class="p">,</span>
        <span class="s1">&#39;british_chain_sears_truncated&#39;</span><span class="p">:</span> <span class="mf">20.116756</span><span class="p">,</span>
        <span class="s1">&#39;cm&#39;</span><span class="p">:</span> <span class="mf">0.01</span><span class="p">,</span>
        <span class="s1">&#39;british_ft&#39;</span><span class="p">:</span> <span class="mf">0.304799471539</span><span class="p">,</span>
        <span class="s1">&#39;british_yd&#39;</span><span class="p">:</span> <span class="mf">0.914398414616</span><span class="p">,</span>
        <span class="s1">&#39;clarke_ft&#39;</span><span class="p">:</span> <span class="mf">0.3047972654</span><span class="p">,</span>
        <span class="s1">&#39;clarke_link&#39;</span><span class="p">:</span> <span class="mf">0.201166195164</span><span class="p">,</span>
        <span class="s1">&#39;fathom&#39;</span><span class="p">:</span> <span class="mf">1.8288</span><span class="p">,</span>
        <span class="s1">&#39;ft&#39;</span><span class="p">:</span> <span class="mf">0.3048</span><span class="p">,</span>
        <span class="s1">&#39;furlong&#39;</span><span class="p">:</span> <span class="mf">201.168</span><span class="p">,</span>
        <span class="s1">&#39;german_m&#39;</span><span class="p">:</span> <span class="mf">1.0000135965</span><span class="p">,</span>
        <span class="s1">&#39;gold_coast_ft&#39;</span><span class="p">:</span> <span class="mf">0.304799710181508</span><span class="p">,</span>
        <span class="s1">&#39;indian_yd&#39;</span><span class="p">:</span> <span class="mf">0.914398530744</span><span class="p">,</span>
        <span class="s1">&#39;inch&#39;</span><span class="p">:</span> <span class="mf">0.0254</span><span class="p">,</span>
        <span class="s1">&#39;km&#39;</span><span class="p">:</span> <span class="mf">1000.0</span><span class="p">,</span>
        <span class="s1">&#39;link&#39;</span><span class="p">:</span> <span class="mf">0.201168</span><span class="p">,</span>
        <span class="s1">&#39;link_benoit&#39;</span><span class="p">:</span> <span class="mf">0.20116782</span><span class="p">,</span>
        <span class="s1">&#39;link_sears&#39;</span><span class="p">:</span> <span class="mf">0.20116765</span><span class="p">,</span>
        <span class="s1">&#39;m&#39;</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">,</span>
        <span class="s1">&#39;mi&#39;</span><span class="p">:</span> <span class="mf">1609.344</span><span class="p">,</span>
        <span class="s1">&#39;mm&#39;</span><span class="p">:</span> <span class="mf">0.001</span><span class="p">,</span>
        <span class="s1">&#39;nm&#39;</span><span class="p">:</span> <span class="mf">1852.0</span><span class="p">,</span>
        <span class="s1">&#39;nm_uk&#39;</span><span class="p">:</span> <span class="mf">1853.184</span><span class="p">,</span>
        <span class="s1">&#39;rod&#39;</span><span class="p">:</span> <span class="mf">5.0292</span><span class="p">,</span>
        <span class="s1">&#39;sears_yd&#39;</span><span class="p">:</span> <span class="mf">0.91439841</span><span class="p">,</span>
        <span class="s1">&#39;survey_ft&#39;</span><span class="p">:</span> <span class="mf">0.304800609601</span><span class="p">,</span>
        <span class="s1">&#39;um&#39;</span><span class="p">:</span> <span class="mf">0.000001</span><span class="p">,</span>
        <span class="s1">&#39;yd&#39;</span><span class="p">:</span> <span class="mf">0.9144</span><span class="p">,</span>
    <span class="p">}</span>

    <span class="c1"># Unit aliases for `UNIT` terms encountered in Spatial Reference WKT.</span>
    <span class="n">ALIAS</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;centimeter&#39;</span><span class="p">:</span> <span class="s1">&#39;cm&#39;</span><span class="p">,</span>
        <span class="s1">&#39;foot&#39;</span><span class="p">:</span> <span class="s1">&#39;ft&#39;</span><span class="p">,</span>
        <span class="s1">&#39;inches&#39;</span><span class="p">:</span> <span class="s1">&#39;inch&#39;</span><span class="p">,</span>
        <span class="s1">&#39;kilometer&#39;</span><span class="p">:</span> <span class="s1">&#39;km&#39;</span><span class="p">,</span>
        <span class="s1">&#39;kilometre&#39;</span><span class="p">:</span> <span class="s1">&#39;km&#39;</span><span class="p">,</span>
        <span class="s1">&#39;meter&#39;</span><span class="p">:</span> <span class="s1">&#39;m&#39;</span><span class="p">,</span>
        <span class="s1">&#39;metre&#39;</span><span class="p">:</span> <span class="s1">&#39;m&#39;</span><span class="p">,</span>
        <span class="s1">&#39;micrometer&#39;</span><span class="p">:</span> <span class="s1">&#39;um&#39;</span><span class="p">,</span>
        <span class="s1">&#39;micrometre&#39;</span><span class="p">:</span> <span class="s1">&#39;um&#39;</span><span class="p">,</span>
        <span class="s1">&#39;millimeter&#39;</span><span class="p">:</span> <span class="s1">&#39;mm&#39;</span><span class="p">,</span>
        <span class="s1">&#39;millimetre&#39;</span><span class="p">:</span> <span class="s1">&#39;mm&#39;</span><span class="p">,</span>
        <span class="s1">&#39;mile&#39;</span><span class="p">:</span> <span class="s1">&#39;mi&#39;</span><span class="p">,</span>
        <span class="s1">&#39;yard&#39;</span><span class="p">:</span> <span class="s1">&#39;yd&#39;</span><span class="p">,</span>
        <span class="s1">&#39;British chain (Benoit 1895 B)&#39;</span><span class="p">:</span> <span class="s1">&#39;british_chain_benoit&#39;</span><span class="p">,</span>
        <span class="s1">&#39;British chain (Sears 1922)&#39;</span><span class="p">:</span> <span class="s1">&#39;british_chain_sears&#39;</span><span class="p">,</span>
        <span class="s1">&#39;British chain (Sears 1922 truncated)&#39;</span><span class="p">:</span> <span class="s1">&#39;british_chain_sears_truncated&#39;</span><span class="p">,</span>
        <span class="s1">&#39;British foot (Sears 1922)&#39;</span><span class="p">:</span> <span class="s1">&#39;british_ft&#39;</span><span class="p">,</span>
        <span class="s1">&#39;British foot&#39;</span><span class="p">:</span> <span class="s1">&#39;british_ft&#39;</span><span class="p">,</span>
        <span class="s1">&#39;British yard (Sears 1922)&#39;</span><span class="p">:</span> <span class="s1">&#39;british_yd&#39;</span><span class="p">,</span>
        <span class="s1">&#39;British yard&#39;</span><span class="p">:</span> <span class="s1">&#39;british_yd&#39;</span><span class="p">,</span>
        <span class="s2">&quot;Clarke&#39;s Foot&quot;</span><span class="p">:</span> <span class="s1">&#39;clarke_ft&#39;</span><span class="p">,</span>
        <span class="s2">&quot;Clarke&#39;s link&quot;</span><span class="p">:</span> <span class="s1">&#39;clarke_link&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Chain (Benoit)&#39;</span><span class="p">:</span> <span class="s1">&#39;chain_benoit&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Chain (Sears)&#39;</span><span class="p">:</span> <span class="s1">&#39;chain_sears&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Foot (International)&#39;</span><span class="p">:</span> <span class="s1">&#39;ft&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Furrow Long&#39;</span><span class="p">:</span> <span class="s1">&#39;furlong&#39;</span><span class="p">,</span>
        <span class="s1">&#39;German legal metre&#39;</span><span class="p">:</span> <span class="s1">&#39;german_m&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Gold Coast foot&#39;</span><span class="p">:</span> <span class="s1">&#39;gold_coast_ft&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Indian yard&#39;</span><span class="p">:</span> <span class="s1">&#39;indian_yd&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Link (Benoit)&#39;</span><span class="p">:</span> <span class="s1">&#39;link_benoit&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Link (Sears)&#39;</span><span class="p">:</span> <span class="s1">&#39;link_sears&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Nautical Mile&#39;</span><span class="p">:</span> <span class="s1">&#39;nm&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Nautical Mile (UK)&#39;</span><span class="p">:</span> <span class="s1">&#39;nm_uk&#39;</span><span class="p">,</span>
        <span class="s1">&#39;US survey foot&#39;</span><span class="p">:</span> <span class="s1">&#39;survey_ft&#39;</span><span class="p">,</span>
        <span class="s1">&#39;U.S. Foot&#39;</span><span class="p">:</span> <span class="s1">&#39;survey_ft&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Yard (Indian)&#39;</span><span class="p">:</span> <span class="s1">&#39;indian_yd&#39;</span><span class="p">,</span>
        <span class="s1">&#39;Yard (Sears)&#39;</span><span class="p">:</span> <span class="s1">&#39;sears_yd&#39;</span>
    <span class="p">}</span>
    <span class="n">LALIAS</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">lower</span><span class="p">():</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">ALIAS</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>

    <span class="k">def</span> <span class="fm">__mul__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">Area</span><span class="p">(</span>
                <span class="n">default_unit</span><span class="o">=</span><span class="n">AREA_PREFIX</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span><span class="p">,</span>
                <span class="o">**</span><span class="p">{</span><span class="n">AREA_PREFIX</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">STANDARD_UNIT</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">*</span> <span class="n">other</span><span class="o">.</span><span class="n">standard</span><span class="p">)}</span>
            <span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">NUMERIC_TYPES</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span>
                <span class="n">default_unit</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span><span class="p">,</span>
                <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">STANDARD_UNIT</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">*</span> <span class="n">other</span><span class="p">)}</span>
            <span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%(distance)s</span><span class="s1"> must be multiplied with number or </span><span class="si">%(distance)s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">{</span>
                <span class="s2">&quot;distance&quot;</span><span class="p">:</span> <span class="n">pretty_name</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">),</span>
            <span class="p">})</span></div>


<div class="viewcode-block" id="Area"><a class="viewcode-back" href="../../../../ref/contrib/gis/measure.html#django.contrib.gis.measure.Area">[文档]</a><span class="k">class</span> <span class="nc">Area</span><span class="p">(</span><span class="n">MeasureBase</span><span class="p">):</span>
    <span class="n">STANDARD_UNIT</span> <span class="o">=</span> <span class="n">AREA_PREFIX</span> <span class="o">+</span> <span class="n">Distance</span><span class="o">.</span><span class="n">STANDARD_UNIT</span>
    <span class="c1"># Getting the square units values and the alias dictionary.</span>
    <span class="n">UNITS</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;</span><span class="si">%s%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">AREA_PREFIX</span><span class="p">,</span> <span class="n">k</span><span class="p">):</span> <span class="n">v</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">Distance</span><span class="o">.</span><span class="n">UNITS</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
    <span class="n">ALIAS</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="s1">&#39;</span><span class="si">%s%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">AREA_PREFIX</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">Distance</span><span class="o">.</span><span class="n">ALIAS</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
    <span class="n">LALIAS</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">lower</span><span class="p">():</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">ALIAS</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>

    <span class="k">def</span> <span class="fm">__truediv__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">NUMERIC_TYPES</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span>
                <span class="n">default_unit</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_default_unit</span><span class="p">,</span>
                <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">STANDARD_UNIT</span><span class="p">:</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">standard</span> <span class="o">/</span> <span class="n">other</span><span class="p">)}</span>
            <span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%(class)s</span><span class="s1"> must be divided by a number&#39;</span> <span class="o">%</span> <span class="p">{</span><span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="n">pretty_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)})</span></div>


<span class="c1"># Shortcuts</span>
<span class="n">D</span> <span class="o">=</span> <span class="n">Distance</span>
<span class="n">A</span> <span class="o">=</span> <span class="n">Area</span>
</pre></div>

          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    <a href="../../../index.html" title="模块代码" accesskey="U">up</a></div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>